from flask import render_template, request

from apps.documents import document_bp
from utils.decorators import login_required, permission_required


@document_bp.route('/')
@login_required
@permission_required('READ_LV1')
def index():
    """文档模块首页视图"""
    # 将所有文档的目录返回给用户
    return render_template('documents/index.html')


@document_bp.route('/show_doc')
@login_required
@permission_required('READ_LV1')
def show_doc():
    """文档展示视图"""
    # 从请求查询字符串中获取文档名
    doc_name = request.args.get('doc_name')
    # 拼接文档路径
    doc_route = 'documents/' + doc_name + '.html'
    # 将文档返回给用户
    return render_template(doc_route)
